cmake_minimum_required(VERSION 3.10)
get_filename_component(PRJ_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PRJ_NAME})

find_package(PkgConfig REQUIRED)
#https://cmake.org/cmake/help/v3.0/module/FindPkgConfig.html


set(SOURCES
        OggAnalyzer.cpp
        OggAnalyzer.h
        OweOggAnalyzer.cpp
        OweOggAnalyzer.h
        )
if (WIN32)

    # all the pkg pc files locations were incorrect, so we cannot rely on it
    #    compile my own opus file
#    add_subdirectory(${OPUSFILE_HOME} ${OPUSFILE_HOME}/cmake-build-debug)
else ()
    pkg_search_module(OPUSFILE REQUIRED IMPORTED_TARGET opusfile)
    pkg_search_module(OPUS REQUIRED IMPORTED_TARGET opus)
    pkg_check_modules(OGG REQUIRED IMPORTED_TARGET ogg)
endif ()

add_definitions(
        #        -DWGS_OWN_PARSING
)
list(APPEND SOURCES
        ThirdPartLibOggAnalyzer.cpp ThirdPartLibOggAnalyzer.h)

add_library(${PROJECT_NAME}
        ${SOURCES}
        )

#message("OPUSINCUDLE: ${OPUS_INCLUDE_DIRS}")

target_include_directories(${PROJECT_NAME} PUBLIC
        ../..
        ${OPUS_INCLUDE_DIRS}
        ${OPUSFILE_INCLUDE_DIRS}
        ${OGG_INCLUDE_DIRS}
        )

#message("OPUSFILE_INCLUDE_DIRS: ${OPUSFILE_INCLUDE_DIRS}, OPUSFILE_LIBRARY_DIRS: ${OPUSFILE_LIBRARY_DIRS}, OPUSFILE_LIBRARIES:${OPUSFILE_LIBRARIES}")
if (WIN32)
#    message("OGG_LIBRARIES: ${OGG_LIBRARIES}, OPUS_LIBRARIES: ${OPUS_LIBRARIES}")

    target_link_libraries(${PROJECT_NAME}
            -L${OGG_LIBRARY_DIRS}
            ${OGG_LIBRARIES}

            -L${OPUS_LIBRARY_DIRS}
            ${OPUS_LIBRARIES}

            -L${OPUSFILE_LIBRARY_DIRS}
            ${OPUSFILE_LIBRARIES}
            )
else ()

    if (TRUE)
        #target_compile_options(${PROJECT_NAME} PUBLIC ${OPUSFILE_CFLAGS_OTHER})
        target_include_directories(${PROJECT_NAME} PUBLIC
                ${OPUSFILE_LIBRARY_DIRS}
                )

        target_link_libraries(${PROJECT_NAME}
                #                PkgConfig::OPUSFILE
                # for opusfile url open
                -L${OPUSFILE_LIBRARY_DIRS}
                ${OPUSFILE_LIBRARIES}
                opusurl
                )
    else ()
        # using my own build opusfile package to fix http unable to seek issue
        # that's becuase of the opusfile library send http request using HTTP 1.0
        # in http.c::2399->op_http_stream_open
        set(OPUSFILE_HOME /Users/guoshunw/Downloads/opusfile/build/install)
        target_include_directories(${PROJECT_NAME} PUBLIC
                ${OPUSFILE_HOME}/include/opus
                )
        target_link_libraries(${PROJECT_NAME}
                -L${OPUSFILE_HOME}/lib
                opusfile
                opusurl
                )
    endif ()
    #    message("OGG_LIBRARY_DIRS:${OGG_LIBRARY_DIRS}")

    target_link_libraries(${PROJECT_NAME}
            -L${OGG_LIBRARY_DIRS}
            -L${OPUS_LIBRARY_DIRS}

            PkgConfig::OGG
            PkgConfig::OPUS
            )

    #    set(LIBOGG_SOURCE_DIR
    #            /Users/guoshunw/CLionProjects/ogg/
    #            )
    #
    #    add_subdirectory(${LIBOGG_SOURCE_DIR}
    #            ${LIBOGG_SOURCE_DIR}/build)

endif ()

target_link_libraries(${PROJECT_NAME} pthread)




